package han.controller;

import han.pojo.Laws;
import han.pojo.LawsMap;
import han.service.LawsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @authou HanDianWei
 * @create 2020-10-27 15:03
 */
@Controller
@RequestMapping("")
public class LawsController {
    @Autowired
    @Qualifier("LawsService")
    private LawsService lawsService;
    //    查找全部的规定的名字和id
    @RequestMapping("allLaws")
    public String list(Model model){
        List<LawsMap> laws = lawsService.queryAllLaws();
        System.out.println(laws);
        model.addAttribute("laws",laws);
        return "tourists/allLaws";
    }
    @RequestMapping("allLawsAdmin")
    public String list1(Model model){
        List<LawsMap> laws = lawsService.queryAllLaws();
        System.out.println(laws);
        model.addAttribute("laws",laws);
        return "admin/allLawsAdmin";
    }
//    进入首页
    @RequestMapping("first")
    public String toFirst(){
        return "first";
    }

//    根据id查找规定
    @RequestMapping("lawDetail/{l_id}")
    public String queryLawsById(@PathVariable("l_id")int id,Model model){
        Laws laws = lawsService.queryLawsById(id);
        List<Laws> lawsList = new ArrayList<Laws>();
        lawsList.add(laws);
        model.addAttribute("lawsDetail",lawsList);
        return "tourists/lawDetail";
    }
//    toAddLaws

    @RequestMapping("toAddLaws")
    public String toAddLaws(){
        return "admin/addLaws";
    }

//    添加
    @RequestMapping("addLaws")
    public String addLaws(Laws laws){
        lawsService.addLaws(laws);
        return "redirect:/allLawsAdmin";
    }
// 修改
    @RequestMapping("toUpd")
    public String toUpdLaws(int id,Model model){
        Laws laws = lawsService.queryLawsById(id);
        model.addAttribute("QLaws",laws);
        return "admin/updLaws";

    }
    @RequestMapping("updLaws")
    public String updLaws(Laws laws){
        lawsService.updLaws(laws);
        return "redirect:/allLawsAdmin";
    }

    //删除
    @RequestMapping("/delLawsById")
    public String delLawsById(int l_id){
        lawsService.delLawsById(l_id);
        return "redirect:/allLawsAdmin";
    }
}
